/*     */ package com.zimbra.cs.account.ldap;
/*     */ 
/*     */ import com.zimbra.common.account.ZAttrProvisioning.AutoProvAuthMech;
/*     */ import com.zimbra.common.account.ZAttrProvisioning.AutoProvMode;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.auth.AuthMechanism.AuthMech;
/*     */ import com.zimbra.cs.account.krb5.Krb5Login;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ import javax.security.auth.login.LoginException;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ class AutoProvisionLazy
/*     */   extends AutoProvision
/*     */ {
/*     */   private String loginName;
/*     */   private String loginPassword;
/*     */   private ZAttrProvisioning.AutoProvAuthMech authedByMech;
/*     */   
/*     */   AutoProvisionLazy(LdapProv prov, Domain domain, String loginName, String loginPassword, ZAttrProvisioning.AutoProvAuthMech authedByMech)
/*     */   {
/*  43 */     super(prov, domain);
/*  44 */     this.loginName = loginName;
/*  45 */     this.loginPassword = loginPassword;
/*  46 */     this.authedByMech = authedByMech;
/*     */   }
/*     */   
/*     */   Account handle() throws ServiceException
/*     */   {
/*  51 */     if (this.domain == null) {
/*  52 */       this.domain = this.prov.getDefaultDomain();
/*  53 */       if (this.domain == null) {
/*  54 */         return null;
/*     */       }
/*     */     }
/*     */     
/*  58 */     if (this.authedByMech == null)
/*     */     {
/*  60 */       this.authedByMech = auth();
/*     */     }
/*     */     
/*  63 */     if (this.authedByMech == null)
/*     */     {
/*     */ 
/*  66 */       return null;
/*     */     }
/*     */     
/*  69 */     if (!autoProvisionEnabled()) {
/*  70 */       return null;
/*     */     }
/*     */     
/*  73 */     return createAccount();
/*     */   }
/*     */   
/*     */   private boolean autoProvisionEnabled() {
/*  77 */     Set<String> authMechsEnabled = this.domain.getMultiAttrSet("zimbraAutoProvAuthMech");
/*  78 */     Set<String> modesEnabled = this.domain.getMultiAttrSet("zimbraAutoProvMode");
/*  79 */     return (authMechsEnabled.contains(this.authedByMech.name())) && (modesEnabled.contains(ZAttrProvisioning.AutoProvMode.LAZY.name()));
/*     */   }
/*     */   
/*     */   private Account createAccount() throws ServiceException {
/*  83 */     AutoProvision.ExternalEntry externalEntry = getExternalAttrsByName(this.loginName);
/*  84 */     String acctZimbraName = mapName(externalEntry.getAttrs(), this.loginName);
/*     */     
/*  86 */     ZimbraLog.autoprov.info("auto creating account in LAZY mode: " + acctZimbraName);
/*  87 */     return createAccount(acctZimbraName, externalEntry, null, ZAttrProvisioning.AutoProvMode.LAZY);
/*     */   }
/*     */   
/*     */   private ZAttrProvisioning.AutoProvAuthMech auth() {
/*  91 */     String authMechStr = this.domain.getAttr("zimbraAuthMech");
/*  92 */     AuthMechanism.AuthMech authMech = null;
/*     */     try
/*     */     {
/*  95 */       authMech = AuthMechanism.AuthMech.fromString(authMechStr);
/*     */     } catch (ServiceException e) {
/*  97 */       ZimbraLog.autoprov.debug("invalid auth mech " + authMechStr, e);
/*     */     }
/*     */     
/*     */ 
/* 101 */     if ((AuthMechanism.AuthMech.ldap == authMech) || (AuthMechanism.AuthMech.ad == authMech)) {
/* 102 */       Map<String, Object> authCtxt = new HashMap();
/*     */       try {
/* 104 */         this.prov.externalLdapAuth(this.domain, authMech, this.loginName, this.loginPassword, authCtxt);
/* 105 */         return ZAttrProvisioning.AutoProvAuthMech.LDAP;
/*     */       } catch (ServiceException e) {
/* 107 */         ZimbraLog.autoprov.info("unable to authenticate " + this.loginName + " for auto provisioning", e);
/*     */       }
/* 109 */     } else if (AuthMechanism.AuthMech.kerberos5 == authMech) {
/*     */       try {
/* 111 */         Krb5Login.verifyPassword(this.loginName, this.loginPassword);
/* 112 */         return ZAttrProvisioning.AutoProvAuthMech.KRB5;
/*     */       } catch (LoginException e) {
/* 114 */         ZimbraLog.autoprov.info("unable to authenticate " + this.loginName + " for auto provisioning", e);
/*     */       }
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 123 */     return null;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/ldap/AutoProvisionLazy.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */